<template>
  <div>
    <el-table border :data="borrowInfoList" style="width: 100%">
      <el-table-column type="index" label="序号" width="80"></el-table-column>
      <el-table-column prop="name" label="借款人姓名"></el-table-column>
      <el-table-column prop="mobile" label="手机"></el-table-column>
      <el-table-column prop="amount" label="借款人金额"></el-table-column>
      <el-table-column label="借款期限">
        <template slot-scope="{ row }">
          {{ row.period + '个月' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="param.returnMethod"
        label="还款方式"
      ></el-table-column>
      <el-table-column prop="param.moneyUse" label="资金用途"></el-table-column>
      <el-table-column label="年化率">
        <template slot-scope="{ row }">
          {{ row.borrowYearRate * 100 + '%' }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="审核状态">
        <template slot-scope="{ row }">
          {{ row.statu == 1 ? '待审核' : '已审核' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="申请时间"
        width="180"
      ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{ row }">
          <el-button
            v-if="row.status == 1"
            @click="approve(row)"
            type="warning"
            size="samll"
          >
            审核
          </el-button>
          <router-link
            v-if="row.status == 2 || row.status == -1"
            :to="`/core/borrowInfo/detail/${row.id}`"
          >
            <el-button type="success" size="samll">查看</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      width="40%"
      title="审批借款信息"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="borrowInfoApprovalVO" label-width="80px">
        <el-form-item label="是否通过">
          <el-radio-group v-model="borrowInfoApprovalVO.status">
            <el-radio label="2">是</el-radio>
            <el-radio label="-1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="标的名称">
          <el-input v-model="borrowInfoApprovalVO.title"></el-input>
        </el-form-item>
        <el-form-item label="起息日">
          <el-date-picker
            v-model="borrowInfoApprovalVO.lendStartDate"
            type="date"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="年化收益">
          <el-input v-model="borrowInfoApprovalVO.lendYearRate">
             <template slot="append">%</template>
          </el-input>
        </el-form-item>
         <el-form-item label="服务费率">
          <el-input v-model="borrowInfoApprovalVO.serviceRate">
             <template slot="append">%</template>
          </el-input>
        </el-form-item>
        <el-form-item label="标的描述">
        <el-input type="textarea" v-model="borrowInfoApprovalVO.lendInfo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="reset">取 消</el-button>
        <el-button type="primary" :disabled="approveBtn" @click="approveSubmit">
          确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      approveBtn:false,
      dialogFormVisible: false,
      borrowInfoList: [],
      borrowInfoApprovalVO: {
        lendYearRate:12,
        serviceRate:5,
        lendStartDate:null,

      },
    }
  },
  methods: {
    reset(){
      // Object.assign(this.$data.borrowInfoApprovalVO,this.$options.data())
      this.borrowInfoApprovalVO = { lendYearRate:12,serviceRate:5,lendStartDate:null}
    },
    async approveSubmit(){
      const result = await this.$API.lend.apperove(this.borrowInfoApprovalVO)       
         this.$message({
          message: result.message,
          type: 'success'
        });
         this.dialogFormVisible = false;
         this.fetchData()
    },
    approve(row) {
      this.dialogFormVisible = true
     // this.lendStartDate = Date.now()
     this.borrowInfoApprovalVO.id = row.id
    },
    async fetchData() {
      const result = await this.$API.borrowInfo.getBorrowInfoList()
      console.log(result)
      if (result.code == 200) {
        this.borrowInfoList = result.data.borrowInfoList
      }
    },
  },
  mounted() {
    this.fetchData()
  },
}
</script>

<style></style>
